package day20171110;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {

        //保存生日信息
        String birthday;

        System.out.println("请输入你的生日信息：");
        Scanner sc = new Scanner(System.in);
        birthday = sc.nextLine();

        //需要将字符转换为整数
/**
 * 2017-11-20 ->time1  毫秒
 * 2017-11-10 ->time2
 *  （time1-time2）/(24*60*60*1000)
 *
 *
 *
 *
 */
        long time1 = 0;
        long time2 = 0;


        try {
            //将字符串转换为日期
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date birthDate = simpleDateFormat.parse(birthday);

            Date curryDate = simpleDateFormat.parse("2017-11-10");


            //将日期转换为Long
            Calendar calendar = Calendar.getInstance();

            calendar.setTime(birthDate);

            //获得星期几

            System.out.println("生日是星期："+(calendar.get(Calendar.DAY_OF_WEEK)+1));
            time1 = calendar.getTimeInMillis();//将日期转换为毫米


            calendar.setTime(curryDate);
            time2 = calendar.getTimeInMillis();//将日期转换为毫米




        } catch (ParseException e) {

        } finally {

            long days = (time1 - time2) / (24 * 60 * 60 * 1000);
            System.out.println(days+"天");

        }


    }
}
